package com.chen.controller;


import com.chen.dto.CreateOrderDto;
import com.chen.service.OrderService;
import com.chen.vo.Result;
import io.swagger.annotations.ApiModelProperty;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author cws
 * @since 2024-11-27
 */
@RestController
@RequestMapping("/mall/order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiModelProperty("创建订单")
    @PostMapping("/createOrder")
    public Result createOrder(@RequestBody CreateOrderDto createOrderDto,@RequestHeader("Authorization") String token) {
        return orderService.createOrder(createOrderDto,token);
    }


    @ApiModelProperty("获取支付订单列表")
    @GetMapping("/getOrderList")
    public Result getOrderPayList(@RequestParam("orderSn") String orderSn) {
        return orderService.getOrderPayList(orderSn);
    }


    @ApiModelProperty("余额支付")
    @PostMapping("/balancePay")
    public Result balancePay(@RequestParam("orderSn") String orderSn,@RequestHeader("Authorization") String token) {
        return orderService.balancePay(orderSn,token);
    }


    @ApiModelProperty("查询全部订单")
    @GetMapping(value = "/list",produces = "application/json;charset=UTF-8")
    public Result list(@RequestParam("status") Integer status) {
        return orderService.OrderAllList(status);
    }


    @ApiModelProperty("修改订单状态")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestParam("id") Long id,@RequestParam("status") Integer status) {
        return orderService.updateStatus(id,status);
    }


    @ApiModelProperty("删除")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return orderService.removeById(id) ? Result.success("删除成功") : Result.fail();
    }

}

